home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / windows / alfacon1.zip / ALFACO.WAS
Text File  |  1992-09-29  |  12KB  |  226 lines

  1. ;Alfacon.Was   v1.00   Alphabetic number converter.
  2.  
  3. ;****************************************************************************
  4. ;*                                                                          *
  5. ;* ALFACON.WAS                                                              *
  6. ;* Copyright (C) 1992 Datastorm Technologies, Inc.                          *
  7. ;* All rights reserved                                                      *
  8. ;*                                                                          *
  9. ;* Purpose:  This is a script which will convert mixed alpha-numeric phone  *
  10. ;*           numbers into all numeric.                                      *
  11. ;*                                                                          *
  12. ;* This Windows ASPECT script allows the user to input a number, in any     *
  13. ;* format, with spaces, parens, hyphens, or any allowable modem characters, *
  14. ;* and convert it into all numbers while leaving the spaces, parens, etc... *
  15. ;*                                                                          *
  16. ;* This ASPECT SCRIPT is intended only as a sample of ASPECT programming.   *
  17. ;* DATASTORM makes no warranty of any kind, express or implied, including   *
  18. ;* without limitation, any warranties of mechantability and/or fitness      *
  19. ;* for a particular purpose.  Use of this program is at your own risk.      *
  20. ;*                                                                          *
  21. ;* Author:  Chris Brandow                                                   * 
  22. ;*                                                                          *
  23. ;****************************************************************************
  24.  
  25. ;****************************************************************************
  26. ;*                                                                          *
  27. ;* MAIN                                                                     *
  28. ;* The procedure Main calls NumberInput which allows the user to input in   *
  29. ;* the number for conversion. For example, 1 314 GIF DATA would be converted*
  30. ;* to 1 314 443 3282.                                                       *
  31. ;*                                                                          *
  32. ;* Calls: NumberInput                                                       *
  33. ;* Modifies globals: none                                                   *
  34. ;*                                                                          *
  35. ;****************************************************************************
  36.  
  37. proc Main
  38.  
  39.    NumberInput()
  40.    
  41. endproc
  42.  
  43. ;****************************************************************************
  44. ;*                                                                          *
  45. ;* NUMBERINPUT                                                              *
  46. ;*                                                                          *
  47. ;* The procedure NumberInput prompts the user for the number to convert.    *
  48. ;* It helps if the number has alpha characters in it, otherwise it really   *
  49. ;* doesn't need converting.                                                 *
  50. ;* The testing of the numbers is done in a function that is                 *
  51. ;* called from NumberInput.  Since only numbers, alpha characters (ex-      *
  52. ;* cluding Q and Z), the asterisk, and the comma are allowable characters, a*
  53. ;* test needs to be done on the string entered by the user.  This test is   *
  54. ;* done in the function legel_entry.  It sets the flag in this procedure to *
  55. ;* tell us that an invalid character was entered into the phone number.     *
  56. ;*                                                                          *
  57. ;* Calls: LegalEntry                                                        *
  58. ;* Called by: Main                                                          *
  59. ;* Modifies globals: none                                                   *
  60. ;*                                                                          *
  61. ;****************************************************************************
  62.  
  63. proc NumberInput
  64.  
  65. string InputNumber
  66. integer flag
  67.  
  68.    flag = 0                                      ; initializes the flag
  69.    while flag == 0
  70.      sdlginput "Converter" "Enter number:" InputNumber     ; allow input
  71.       if success                                 ; if successful
  72.          flag = LegalEntry(&InputNumber)         ; test digits for alphas
  73.          if flag == 0                            ; if an invalid character
  74.             ErrorEncountered()                   ; call the error procedure
  75.          endif
  76.       else                                       ; if the cancel was hit
  77.          halt                                    ; halt the program
  78.       endif   
  79.    endwhile
  80.    usermsg "The number is %s" InputNumber        ; output converted number
  81. endproc   
  82.  
  83. ;****************************************************************************
  84. ;*                                                                          *
  85. ;* LEGALENTRY(InputNumber)                                                  *
  86. ;* Returns: InputNumber = 0 showing that in invalid character was entered.  *
  87. ;* The function LegalEntry is the function that tests the number that has   * 
  88. ;* been input by the user. A string of possible characters has been included*                                                  
  89. ;* as a local.  This string is used so that if someone needs to add or take *
  90. ;* away characters, they may do so with ease and less confusion.            *
  91. ;* The number that was entered by the user is pulled apart one character at *
  92. ;* a time and a strfind is done to test whether each character is a valid   *
  93. ;* one.  If it is not, an error will appear on the screen and the user will *
  94. ;* be allowed to either reenter the number or quit the program.  If the     *
  95. ;* number is in the list and is in position 16 or higher (meaning it was a  *
  96. ;* letter), then control is passed to a conversion procedure which will do  *
  97. ;* conversion and then pass the new character back to LegalEntry for a      *
  98. ;* strpoke to be performed to include it into the final phone number.       *
  99. ;*                                                                          *
  100. ;* Calls: Convert2Number                                                    *
  101. ;* Called by: NumberInput                                                   *
  102. ;* Modifies globals: none                                                   *
  103. ;*                                                                          *
  104. ;****************************************************************************
  105.  
  106. func LegalEntry:integer
  107.  
  108. strparm InputNumber
  109. integer counter, NumberLength, EndValue, TempValue, StrPos
  110. string TempString
  111.  
  112. string OKValues = "0123456789,*()- ABCDEFGHIJKLMNOPRSTUVWXY"
  113.  
  114.  
  115.    strupr InputNumber                            ; convert # to uppercase 
  116.    strlen InputNumber NumberLength               ; get length of #
  117.    EndValue = NumberLength - 1                   ; set counter EndValue
  118.                                                  ; since positions start at 0
  119.    for counter = 0 upto EndValue
  120.       breakpoint
  121.       strpeek InputNumber counter TempValue      ; get the ASCII value
  122.       strfmt TempString "%c" TempValue
  123.       if strfind OKValues TempString StrPos
  124.          if StrPos > 15
  125.             Convert2Number(&TempValue)           ; call Convert2Number   
  126.             strpoke InputNumber counter TempValue; insert character
  127.          endif
  128.       else
  129.          return(0)
  130.       endif
  131.  
  132.    endfor
  133.  
  134.    return(1)                                     ; this return signals that
  135.                                                  ; the number was a numeral
  136. endfunc
  137.          
  138. ;****************************************************************************
  139. ;*                                                                          *
  140. ;* CONVERT2NUMBER(TempValue)                                                *
  141. ;*                                                                          *
  142. ;* The procedure Convert2Number is what is activated if the user inputs     *
  143. ;* an alpha character into the phone number.  The program takes into con-   *
  144. ;* sideration above in procedure LegalEntry if the character was a Q or a   *
  145. ;* Z.  Since these are not represented on the phone, they are not allowable *
  146. ;* entries.                                                                 *
  147. ;*                                                                          *
  148. ;* Calls: nothing                                                           *
  149. ;* Called by: LegalEntry                                                    *
  150. ;* Modifies globals: none                                                   *
  151. ;*                                                                          *
  152. ;****************************************************************************
  153.  
  154. proc Convert2Number
  155.  
  156. intparm TempValue
  157.  
  158.    if TempValue > 64 && TempValue < 68           ; test for A - C and turn
  159.       TempValue = 50                             ; the strpoke value into 2
  160.    endif
  161.  
  162.    if TempValue > 67 && TempValue < 71           ; test for D - F and turn
  163.       TempValue = 51                             ; the strpoke value into 3
  164.    endif
  165.  
  166.    if TempValue > 70 && TempValue < 74           ; test for G - I and turn
  167.       TempValue = 52                             ; the strpoke value into 4
  168.    endif
  169.  
  170.    if TempValue > 73 && TempValue < 77           ; test for J - L and turn
  171.       TempValue = 53                             ; the strpoke value into 5
  172.    endif
  173.          
  174.    if TempValue > 76 && TempValue < 80           ; test for M - O and turn
  175.       TempValue = 54                             ; the strpoke value into 6
  176.    endif
  177.  
  178.    if TempValue > 79 && TempValue < 84           ; test for P - S without Q,
  179.       TempValue = 55                             ; as tested for above, and 
  180.    endif                                         ; set the strpoke value to 7
  181.  
  182.    if TempValue > 83 && TempValue < 87           ; test for T - V and turn
  183.       TempValue = 56                             ; the strpoke value into 8 
  184.    endif
  185.  
  186.    if TempValue > 86 && TempValue < 91           ; test for W - Y and turn
  187.       TempValue = 57                             ; the strpoke value into 9
  188.    endif
  189.            
  190. endproc
  191.  
  192. ;****************************************************************************
  193. ;*                                                                          *
  194. ;* ERRORENCOUNTERED                                                         *
  195. ;*                                                                          *
  196. ;* The procedure ErrorEncountered is called if the flag in the procedure    *
  197. ;* NumberInput is set to a zero.  This signals a zero and tells us that an  *
  198. ;* invalid character was entered.  It then asks if you wish to reenter the  *
  199. ;* number or if you want to just forget about it.                           *
  200. ;*                                                                          *
  201. ;* Calls: nothing                                                           *
  202. ;* Called by: NumberInput                                                   *
  203. ;* Modifies globals: none                                                   *
  204. ;*                                                                          *
  205. ;****************************************************************************
  206.  
  207. proc ErrorEncountered
  208.  
  209. integer MsgValue
  210.  
  211. ;****************************************************************************
  212. ;* MACRO DEFINITIONS                                                        *
  213. ;****************************************************************************
  214.  
  215. #define ERROR1MESSAGE "A character that could not be dialed was entered."
  216. #define ERROR2MESSAGE "Would you like to try again?"
  217.  
  218.    sdlgmsgbox "Error!" ERROR1MESSAGE EXCLAMATION OK MsgValue
  219.    sdlgmsgbox "Quit?" ERROR2MESSAGE QUESTION YESNO MsgValue
  220.    if MsgValue == 7                             ; if the user says 'no' then
  221.       halt                                       ; halt the program
  222.    endif
  223.  
  224. endproc
  225.  
  226.